package com.test.shardingjdbc.algorithm;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

/**
 * @author sunchuanyin
 * @version 1.0
 * @description 日期分片策略
 * @date 2022/5/4 2:42 下午
 */
public class TimeShardingAlgorithm implements PreciseShardingAlgorithm<String> {
    private static final String SPLITTER = "_";

    /**
     *
     * @param collection 分表的集合
     * @param preciseShardingValue 分表字段（找到需要的表）
     * @return
     */
    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<String> preciseShardingValue) {
        String tbName = preciseShardingValue.getLogicTableName() + SPLITTER + preciseShardingValue.getValue();
        System.out.println("Sharding input:" + preciseShardingValue.getValue() + ", output:{}" + tbName);
        return tbName;
    }
}
